Metaprogramming Elixir by Chris McCord

Metaprogramming Elixir by Chris McCord

Author:Chris McCord
Language: eng
Format: epub, pdf
Tags: Pragmatic Bookshelf
ISBN: 978-1-68050-041-7
Publisher: The Pragmatic Bookshelf, LLC


​- ​@locales​ {name, mappings}

​- ​end​

​20 ​end​

​-

​- ​def​ compile(translations) ​do​

​- ​# TBD: Return AST for all translation function definitions​

​- ​end​

​25 ​end​

Just like our accumulated @tests attribute in our Assertion module from the ​code​​​, we registered an accumulated @locales attribute on line 5. Next, we wired up the __before_compile__ hook in our Translator.__using__ macro. On line 13, we added a placeholder to delegate to a compile function to carry out the code generation from our locale registrations, but we left the compile implementation for a later step. Finally, we defined our locale macro that will register a locale name and list of translations to be used by compile in our __before_compile__ hook.

With the accumulated attribute registrations wired up, we have all the necessary information to produce an AST of t/3 function definitions. If you like recursion, you’re in for a treat. If not, pay attention and we’ll break it down.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.